﻿<!--#Include File = "CustomTemplate.asp" -->

<%
	Call  PageController.RenderPage()
	Public Function Page_Configure()
		PageController.PageTitle = "List comment"
		PageController.AuthorizedRoles =  Array("publisher")
		pageController.RequiresAuthentication  = True
		PageController.PageCSSFiles = "main.css" 	
		
	End function
%>
<%Public Function Page_RenderForm()%>
	<H2>List comment</H2>
	
	<%	Page.Execute %>
	<Span Class="Caption">List comment<HR></Span>	

	<%gdComment%>	
	
	<hr>
	
<%End Function%>


<%  'This would normaly go in a another page, but for the sake of simplicity and to minimize the number of pages
    'I'm including code behind stuff here...	
	Dim gdComment
		
	Public Function Page_Init()
		
		Set gdComment = New_ServerDataGrid("gdComment")		
		Page.AutoResetScrollPosition = True
	End Function

	Public Function Page_Controls_Init()						
	End Function
	
	Public Function Page_PreRender()						
		Call ShowRecords()
	End Function
	
Public Sub SetTemplate(obj)		 
	obj.AlternatingItemStyle = "background-color:#dddddd;font-size:8pt;border:1px solid black" 
	obj.ItemStyle = "font-size:8pt;border:1px solid black"
	obj.Control.Style = "width:100%;border-collapse:collapse;"
	obj.HeaderStyle = "font-weight:bold;color:white;background-color:#4682b4;font-size:10pt;font-family:tahoma;border:1px solid black"
	obj.BorderWidth = 1
	obj.BorderColor = "Black"
	obj.GenerateColumns() 'Just so it generates most of them :-)
	obj.CreateColumns Array("contenttitle" , "title","body", "fullname", "email", "createtime", "username","status","") , Array("Content Title", "Comment Title","Comment","Sender","Email","Create Time", "User Approval","Status", "Action")
	obj.AutoGenerateColumns = False  'Now lets not have it generate the columns again during render!
	
	
	obj.Columns(7).ColumnType = 3    'Modify the column settings we need.
	obj.Columns(7).CellRenderFunctionName = "RenderStatusColumn"
	
	
	obj.Columns(8).ColumnType = 3    'Modify the column settings we need.
	obj.Columns(8).HeaderText = "Actions"
	obj.Columns(8).HorizonalAlign = "center"
	obj.Columns(8).CellRenderFunctionName = "RenderActionColumn"
	
	
	obj.Pager.ProgressStyle = "font-size:8pt"
	obj.Pager.PrevNextStyle = "font-size:8pt"
	obj.Pager.PagerStyle    = "font-size:8pt"
	obj.AllowPaging = True
	
	
End Sub

Public Function RenderStatusColumn(ds)
		if ds("status").Value = 0 then
			Response.Write("Created")
		elseif ds("status").Value = 1 then
			Response.Write("Allowed publish")
		elseif ds("status").Value = 2 then
			Response.Write("Denied publish")
		end if
End Function


Public Function RenderActionColumn(ds)
		
		If ds("status") =0  Then
			Response.Write "<A " & Page.GetEventScript("HREF","Page","AllowComment",ds("id").Value,"") & " Class='ActionLink'>Allow</a> | "
			Response.Write "<A " & Page.GetEventScript("HREF","Page","DenyComment",ds("id").Value,"") & " Class='ActionLink'>Deny</a>"
		End If
End Function

Public Function Page_AllowComment(e)
	Dim sSQL
		Dim rs
		sSQL = "SELECT * FROM comment Where id=" & Replace(e.Instance,"'","''")
		
		Set rs = DBLayer.GetRecordSet(sSQL)		
		If rs.RecordCount = 0 Then
			Exit Function
		End If			
		
		rs("status").Value	= 1	' allow
		
		rs("userapproval").Value =CurrentUser.UserID()
		rs("approvaltime").Value = Now()
		DBLayer.UpdateRecordSet rs
End Function
Public Function Page_DenyComment(e)
	Dim sSQL
		Dim rs
		sSQL = "SELECT * FROM comment Where id=" & Replace(e.Instance,"'","''")
		
		Set rs = DBLayer.GetRecordSet(sSQL)		
		If rs.RecordCount = 0 Then
			Exit Function
		End If			
		
		rs("status").Value	= 2	' Deny
		rs("userapproval").Value =CurrentUser.UserID()
		rs("approvaltime").Value = Now()
		DBLayer.UpdateRecordSet rs
End Function


Public Function ShowRecords()
	Dim sSQL
	sSQL = "SELECT c.title as contenttitle, a.*, u.username FROM comment as a inner join content as c on a.contentid = c.id " & _
		"left join [user] as u on u.id =a.userapproval"
	
	Set gdComment.DataSource = GetRecordset(sSQL)

	SetTemplate gdComment

End Function


		
	
%>